package com.cup.plat.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import com.cup.plat.annotation.RequireAuth;

@Component
@Aspect
public class AuthenticationAspect {
	
	 @Pointcut("@annotation(com.cup.plat.annotation.RequireAuth)")
	 public void requireAuth(){}
	 
	 @Before("requireAuth()")
	 public void doBefore(JoinPoint joinPoint){
		 System.out.println("my define annotation");
		 
		 MethodSignature signature = (MethodSignature)joinPoint.getSignature();
		 
		 RequireAuth annotation = signature.getMethod().getAnnotation(RequireAuth.class);
		 
		String[] roles = annotation.roles();
		for(String role : roles) {
			System.out.println("roles:"+role);
		}
		 
	 }

}
